class Solution {
public:
    string simplifyPath(string path) {
        vector<string> sta;
        stringstream ss(path);
        string token;
        while(getline(ss,token,'/')){
            if(token == "" || token == ".")continue;
            else if(token == ".."){
                if(!sta.empty())sta.pop_back();
            }else{
                sta.push_back(token);
            }
        }
        if(sta.empty())return "/";
        string res;
        for(const string& s:sta)res += "/" + s;
        return res;
    }
};
